<?php

class actChatNicknameChange extends action
{
	function execute($m)
	{
		// Get the respective input.
		$key      = $this->getInput('k') or $this->doAjaxError();
		$nickname = $this->getInput('n') or $this->doAjaxError();
		
		// Check if the key is correct.
		$this->checkKey($key) or $this->doAjaxError();
		
		// Update the database
		$uM = $m->getModel('user') or $this->doAjaxError();
		
		// Set the user to the logged in user.
		$uM->setUser(-1) or $this->doAjaxError();
		
		// Set new nickname
		$uM->setNickname($nickname);
		
		// Save action
		$this->act($m, $uM->getID() . ',nickname,' . $nickname, 'contacts');
		
		// Set new key and finish
		$this->setNewKey();
		
		// output the nickname that has been set
		$this->addOutput($uM->getNIckname());
		
		$this->finish();
		
	} // end function
	
} // end class

$_ = 'actChatNicknameChange';

?>